﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;
using BSCMFF.Core.Exceptions.Database;

namespace BSCMFF.Web.UserControls.Details
{
    public partial class KPIProgressDetails : System.Web.UI.UserControl
    {
        public KPI_Progress kpip;

        public KPI_Progress KPIP
        {
            get
            {
                
                return kpip;
            }
            set
            {
                kpip = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            KPI_Progress k;// k.s

        }

        protected void RadButtonSave_Click(object sender, EventArgs e)
        {
            BSCEntities context = new BSCEntities();
            /*int kpipID = Int32.Parse(HiddenFieldKPIPID.Value);

            KPI_Progress kpip = (from kpips in context.KPI_Progress
                                 where kpips.KPI_Progress_ID == kpipID
                                 select kpips).SingleOrDefault();
            
            kpip.Weight = (int)RadNumericTextBoxWeight.Value;
            kpip.Start_Value = (double)RadNumericTextBoxStartValue.Value;
            kpip.Target_Value = (double)RadNumericTextBoxTargetValue.Value;

            kpip.Min = RadNumericTextBoxMin.Value == null ? (double)RadNumericTextBoxStartValue.Value : (double)RadNumericTextBoxMin.Value;
            kpip.Max = RadNumericTextBoxMax.Value == null ? (double)RadNumericTextBoxTargetValue.Value : (double)RadNumericTextBoxMax.Value;

            kpip.Current_Value = RadNumericTextBoxCurrentValue.Value == null ? (double)RadNumericTextBoxStartValue.Value : (double)RadNumericTextBoxCurrentValue.Value;
            */
            try
            {
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new InconsistentDatabaseException("Couldn't update KPI Progress : " + ex.Message);
            }
        }
    }
}